<?php

require("top.ajax.php");

if(isset($_GET['type'])){
    $type = $_GET['type'];
	
    switch($type){
		/* Concerne un utilisateur */
        case "user":
            if(isset($_GET['id'])) {
                $id_user = $_GET['id'];
                if(User::existUser($id_user)){
                    $user = new User($id_user);
                    
					if(isset($_GET['content'])){
                        $content = $_GET['content'];
                        
						switch($content){
							/* Amis */
                            case "friends":
								$friends = $user->getFriends();
								
								/* Amis soutenant une association */
								if(isset($_GET['support'])) {
                               		$assoc = new Association($_GET['support']);
									$supports = array();
									foreach($friends as $f) {
										if($assoc->isSupporting($f)) {
											$supports[] = $f;
										}
									}
									$friends = $supports;	
								} 
								
                                if(isset($_SESSION['user'])) {
                                    $isFriend = array();
                                    foreach($friends as $friend){
                                        if($_SESSION['user']->isFriend($friend['id'])){
                                            $isFriend[$friend['id']] = true;
                                        }else{
                                            $isFriend[$friend['id']] = false;
                                        }
                                    }
                                    $tpl->assign('isFriend',$isFriend);
                                }
                                $tpl->assign('friends',$friends);
                                $tpl->assign('user', $user);
                                $template = "friends.tpl";
                                break;

                            case "wishlist":
                                $tpl->assign("products", $user['wishlist']);
                                $template = "products.tpl";
                                break;

                            case "purchases":
                                $tpl->assign("products", $user['purchases']);
                                $template = "products.tpl";
                                break;
						}
                    }
                }
            }
            break;
    }
}

/* Affichage */
$tpl->display('ajax/seeall/'.$template);
?>
